/**
 * @author rococo
 * @email [3936636@qq.com]
 * @create date 2021-04-20 15:12:12
 * @modify date 2021-04-20 21:47:28
 * @desc [Store]
 */

import { createStore } from "vuex";

export default createStore({
  // 用来定义所需要的状态
  state: {
    list: [
      {
        title: "吃饭",
        complete: false,
      },
      {
        title: "睡觉",
        complete: false,
      },
      {
        title: "敲代码",
        complete: true,
      },
    ],
  },
  // 用来同步修改state的
  mutations: {
    /**
     * 添加任务
     * @param {*} state
     * @param {*} payload
     */
    addTodo(state, payload) {
      state.list.push(payload);
    },

    /**
     * 删除任务
     * 删除 splice（下标，个数）
     * @param {*} state
     * @param {*} payload
     */
    delTodo(state, payload) {
      state.list.splice(payload, 1);
    },

    /**
     * 清除已完成
     * 把过滤之后的数组传进来替换即可
     * @param {*} state
     * @param {*} payload
     */
    clearTodo(state, payload) {
      state.list = payload;
    },
  },
  // 用来异步提交mutation
  actions: {},
  // 模块化
  modules: {},
});
